import json
from models import BaseModels
from sqlalchemy import Column, String, BigInteger, ForeignKey, Integer, DateTime


class Aircraft(BaseModels):
    __tablename__ = 'aircraft'
    id = Column(BigInteger, autoincrement=True, primary_key=True, unique=True, nullable=False)
    aircraft = Column(String(64), nullable=False, unique=True, comment="机种名称")
    specification = Column(String(64), nullable=True, comment="产品规格")
    route_id = Column(Integer, ForeignKey("routes.id"), comment="对应的路径ID")
    time = Column(DateTime, nullable=False, comment="机种创建时间")

    def __repr__(self):
        return json.dumps({
            "aircraft_id": self.id,
            "aircraft": self.aircraft,
            "specification": self.specification,
            "route_id": self.route_id,
            "time": self.time.strftime("%Y-%m-%d %H:%M:%S") if self.time else None
        })
